﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Centrica.TaskManager.Data;

using Telerik.Windows.Data;
using Telerik.Windows.Controls;

namespace Centrica.TaskManager.Task
{
    /// <summary>
    /// Interaction logic for TasksView.xaml
    /// </summary>
    public partial class TasksView : UserControl
    {
        private TasksViewModel _viewModel;

        public TasksView(TasksViewModel viewModel)
        {
            InitializeComponent();

            DataContext = viewModel;

            _viewModel = viewModel;
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            ContextMenu contextMenu = (ContextMenu)((HeaderedItemsControl)sender).Parent;

            Data.Task task = (Data.Task)((RadRowItem)contextMenu.PlacementTarget).DataItem;

            string menu = (string)((MenuItem)sender).Header;

            switch (menu)
            { 
            
                case "Add":

                    _viewModel.AddTaskCommand.Execute(task);

                    break;
            
                case "Delete":

                    _viewModel.DeleteTaskCommand.Execute(task);

                    break;

                case "Edit":

                    _viewModel.EditTaskCommand.Execute(task);
                    
                    break;
                                
            }

        }

    }
}
